﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WinformMapXpSupportDemo.Model
{
    /// <summary>
    /// 公共事件参数
    /// </summary>
    public class ObjectEventArgs : EventArgs
    {
        public object Tag { get; set; }
    }

    public class MapPosition
    {
        /// <summary>
        /// 经度
        /// </summary>
        public double Longitude { get; set; }
        /// <summary>
        /// 纬度
        /// </summary>
        public double Latitude { get; set; }

        public MapPosition(double lng,double lat)
        {
            this.Longitude = lng;
            this.Latitude = lat;
        }
    }
    /// <summary>
    /// 地图JS对象，提供给JS用来调用C#代码
    /// </summary>
    public class AMapJsObject
    {
        private Form _ParentFrom;
        public AMapJsObject(Form parentFrom)
        {
            this._ParentFrom = parentFrom;
        }

        /// <summary>
        /// 坐标改变事件
        /// </summary>
        public event EventHandler<ObjectEventArgs> OnMapPositionChanged;
        /// <summary>
        /// 地址改变事件
        /// </summary>
        public event EventHandler<ObjectEventArgs> OnAddressChanged;

        /// <summary>
        /// 地图经纬度坐标对象
        /// </summary>
        public MapPosition MapPosition { get; set; }
        /// <summary>
        /// 地理名称
        /// </summary>
        public string Address { get; set; }
        /// <summary>
        /// 更新经纬度
        /// </summary>
        /// <param name="obj"></param>
        public void UpdateLngLat(double lng,double lat)
        {
            MapPosition = new MapPosition(lng, lat);
            ObjectEventArgs arg = new ObjectEventArgs();
            arg.Tag = new MapPosition(lng, lat);
            OnMapPositionChanged?.Invoke(null, arg);
        }
        /// <summary>
        /// 更新地址
        /// </summary>
        /// <param name="address"></param>
        public void UpdateAddress(string address)
        {
            this.Address = address;
            ObjectEventArgs arg = new ObjectEventArgs();
            arg.Tag = address;
            OnAddressChanged?.Invoke(null, arg);
        }
        /// <summary>
        /// 显示信息
        /// </summary>
        /// <param name="content">信息内容</param>
        /// <param name="caption">标题</param>
        /// <param name="messageType">信息类型</param>
        public void ShowMessage(string content,string caption,string messageType="")
        {
            MessageBoxIcon icon = MessageBoxIcon.Information;
            Enum.TryParse<MessageBoxIcon>(messageType, out icon);
            MessageBox.Show(_ParentFrom,content, caption, MessageBoxButtons.OK, icon);
        }

    }
}
